function bubbleSort(arr) {
    var len = arr.length;
    for(let i=0;i<len;i++) {
        for (let j=0;j<len;j++) {
            if(arr[j] > arr[j+1]) {
                var temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
        }
    }
    return arr;
}

var a = [0,4,1,3,2,6,17,419,22,46];
console.log(bubbleSort(a));